home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / aspell22.zip / ORPHCHK.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-03  |  24KB  |  461 lines

  1. unit Orphchk;
  2.  
  3. interface
  4.  
  5. { IMPORTANT: This component REQUIRES that you have Turbo Power's Orpheus
  6.   components installed.  It makes use of the Orpheus TOVCCustomEditor so
  7.   you can spell check the following Orpheus editor types with the OrphCheck
  8.   method: TOvcCustomEditor, TOvcEditor, TOvcCustomTextEditor, TOvcTextFileEditor
  9.   and TOvcdbEditor.
  10.   None of Turbo Power's units, components or source is included with this package
  11.   as that would be illegal redistribution of their product.  However, if you
  12.   have a need for a large editor (files up to 16 megabytes) to replace TMemo
  13.   I would highly recommend you purchase Turbo Power's Orpheus package.  Besides
  14.   the large editors it also provides a large number of useful and powerful
  15.   components for Delphi such as:
  16.  
  17.      Large virtual list boxes, numerous data entry types, array editors,
  18.      Table components, spinners, rotated labels, timers and much more.
  19.  
  20.   Turbo Power Software can be reached at: 1-800-333-4160                    }
  21.  
  22.  
  23.  { Revisions:
  24.       1/24/96  - Added ShowStatus property
  25.       1/31/96  - Fixed problem with Orphues' SetSelection not showing highlighted text
  26.                - Minor speed up in GetNextWord/StripWord
  27.       2/8/96   - Made spelling suggestion window always visible
  28.                - ShowStatus removed now that dialog is always visible
  29.                - MaxSuggest is now 255 (was limited to 30)
  30.                - AvoidHighlight property added
  31. }
  32.  
  33.  
  34. uses
  35.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  36.   Forms, Dialogs, StdCtrls, SugDialg, OvcBase, OvcData, OvcEdit;
  37.                                              { ^ Orpheus units needed  ^}
  38.  
  39. type SuggestionType = (stNoSuggest, stCloseMatch, stPhoneme);
  40.  
  41. type
  42.   TOrphSpell = class(TComponent)
  43.   private
  44.     { Private declarations }
  45.     FSuggestType         : SuggestionType;  { Holds the default initial suggestion type }
  46.     FDictionaryMain      : string;          { Holds the name of the main dictionary file }
  47.     FDictionaryUser      : string;          { Holds the name of the user's custom dictionary file }
  48.     FSuggestMax          : byte;            { Holds the maximum number of suggestions to return }
  49.     UserDictID           : integer;         { Holds the ID number ofhte open user dictionary }
  50.     FLeaveDictionaryOpen : boolean;         { Should we leave the dictionary files open? }
  51.     FDictionaryOpen      : boolean;         { Is the dictionary open? }
  52.     FAvoidHighlight      : boolean;         { Should the dialog avoid the highlighted text? }
  53.   protected
  54.     { Protected declarations }
  55.     DictDataPtr: pointer;                  { Pointer to internal dictionary data }
  56.     SuggestDlg : TSugDialog;               { The dialog box for this component }
  57.     StartWord  : string;                   { Temporary place to store the word being tested }
  58.     IgnoreList : TStringList;              { List of words to ignore }
  59.     ReplaceList   : TStringList;           { Replacement word list }
  60.     AlternateList : TStringList;           { Replacement word alternate word list }
  61.     procedure BaseCheckOrph(var TheEditor : TOvcCustomEditor;
  62.                             StartLine : longint; StartCol : integer;
  63.                             EndLine   : longint; EndCol   : integer);
  64.     procedure SetDialogPosition(var TheEditor : TOvcCustomEditor; SelectLine : longint);
  65.   public
  66.     { Public declarations }
  67.     UserDictionaryOpen : boolean;                 { Record if the custom user dictionary was opened ok }
  68.     constructor Create(AOwner : TComponent); override;  { Standard create method }
  69.     procedure Free;                        { Standard free method }
  70.     procedure SetMaximumSuggestions(Max : byte);      { Method to set the maximum number of suggestions }
  71.     procedure SetDictionaryMain(Filename : string);   { Set a new main dictionary filename }
  72.     procedure SetDictionaryUser(Filename : string);   { Set a new user dictionary filename }
  73.     property DictionaryOpen : boolean read FDictionaryOpen;
  74.  published
  75.     { Published declarations }
  76.     procedure CheckOrph(TheEditor : TOvcCustomEditor);   { Main method, check the spelling of a Orpheus Editor types }
  77.     procedure CheckOrphSelection(TheEditor : TOvcCustomEditor); { Alternate method to check only selected text }
  78.     procedure ClearLists;                                { Method to clear the ignore/replace lists }
  79.     property SuggestType : SuggestionType read FSuggestType write FSuggestType default stCloseMatch;
  80.        { Get/Set the initial suggestion type }
  81.     property DictionaryMain : string read FDictionaryMain write FDictionaryMain;
  82.        { Get/Set the name of the main dictionary file }
  83.     property DictionaryUser : string read FDictionaryUser write FDictionaryUser;
  84.        { Get/Set the name of the user dictionary file }
  85.     property MaxSuggestions : byte read FSuggestMax write SetMaximumSuggestions default 10;
  86.        { Get/Set the maximum number of suggestions }
  87.     property LeaveDictionariesOpen : boolean read FLeaveDictionaryOpen write FLeaveDictionaryOpen default TRUE;
  88.        { Get/Set whether the dictionary should be opened/closed after each call }
  89.     property AvoidHighlight : boolean read FAvoidHighlight write FAvoidHighlight default true;
  90.        { Get/Set whether the highlight should be avoided by the dialog }
  91.   end;
  92.  
  93.  
  94. procedure Register;
  95.  
  96. implementation
  97.  
  98. uses BaseASpl;
  99.  
  100.  
  101. procedure Register;  { Standard component registration procedure }
  102. begin
  103.   RegisterComponents('Samples', [TOrphSpell]);
  104. end;
  105.  
  106.  
  107. constructor TOrphSpell.Create(AOwner : TComponent);
  108. { Standard create method }
  109. begin
  110.   inherited Create(AOwner);           { Make sure the base component to made }
  111.   FSuggestType := stCloseMatch;       { Set the default values }
  112.   FAvoidHighlight := true;
  113.   FDictionaryMain := 'acrop.dct';
  114.   FDictionaryUser := 'custom.dct';
  115.   FLeaveDictionaryOpen := TRUE;
  116.   FDictionaryOpen  := FALSE;
  117.   UserDictionaryOpen := FALSE;
  118.   FSuggestMax     := 10;
  119.   IgnoreList := TStringList.Create;   { Create the list of ignored words }
  120.   IgnoreList.Clear;                   { And set it to the way it is needed to be }
  121.   IgnoreList.Sorted := TRUE;
  122.   ReplaceList := TStringList.Create;   { Create the list of words to replace }
  123.   ReplaceList.Clear;                   { And set it up }
  124.   ReplaceList.Sorted := FALSE;
  125.   AlternateList := TStringList.Create; { Create the list of words to replace with }
  126.   AlternateList.Clear;                 { And set it up }
  127.   AlternateList.Sorted := FALSE;
  128.   InitDictionaryData(DictDataPtr);        { Create the internal dictionary data }
  129.   SuggestDlg := TSugDialog.Create(Self);  { Create the dialog box }
  130.   SuggestDlg.DictDataPtr := DictDataPtr;  { And let it know the internal data address }
  131. end;
  132.  
  133. procedure TOrphSpell.Free;
  134. { Standard free method }
  135. begin
  136.   if FDictionaryOpen then
  137.     BaseASpl.CloseDictionaries(DictDataPtr);
  138.   ReleaseDictionaryData(DictDataPtr);
  139.   IgnoreList.Free;     { Get rid of the ignore list }
  140.   ReplaceList.Free;    { Get rid of the replacement list }
  141.   AlternateList.Free;  { Get rid of the replacement word list }
  142.   SuggestDlg.Free;     { Get rid of the suggestion dialog box }
  143.   inherited Free;      { and then the base component }
  144. end;
  145.  
  146. procedure TOrphSpell.SetMaximumSuggestions(Max : byte);
  147. { Set the maximum number of suggestions to return }
  148. begin
  149.   FSuggestMax := Max;   { And store the value }
  150. end;
  151.  
  152. procedure TOrphSpell.SetDictionaryMain(Filename : string);
  153. begin
  154.   if FDictionaryOpen or UserDictionaryOpen then
  155.     begin
  156.       BaseASpl.CloseDictionaries(DictDataPtr);  { Close the dictionaries since filename is changing }
  157.       FDictionaryOpen := FALSE;                 { Mark them as not opened }
  158.       UserDictionaryOpen := FALSE;
  159.     end;
  160.   FDictionaryMain := Filename;
  161. end;
  162.  
  163. procedure TOrphSpell.SetDictionaryUser(Filename : string);
  164. begin
  165.   if FDictionaryOpen or UserDictionaryOpen then
  166.     begin
  167.       BaseASpl.CloseDictionaries(DictDataPtr);  { Close the dictionaries since filename is changing }
  168.       FDictionaryOpen := FALSE;                 { Mark them as not opened }
  169.       UserDictionaryOpen := FALSE;
  170.     end;
  171.   FDictionaryUser := Filename;
  172. end;
  173.  
  174. procedure TOrphSpell.ClearLists;
  175. begin
  176.   IgnoreList.Clear;                    { Clear the ignore list }
  177.   IgnoreList.Sorted := TRUE;
  178.   ReplaceList.Clear;                   { Clear the list of words to replace }
  179.   ReplaceList.Sorted := FALSE;
  180.   AlternateList.Clear;                 { Clear the list of words to do the replacing with }
  181.   AlternateList.Sorted := FALSE;
  182. end;
  183.  
  184.  
  185. procedure TOrphSpell.SetDialogPosition(var TheEditor : TOvcCustomEditor; SelectLine : longint);
  186. { Set the position of the Suggestion Dialog based on the current line.
  187.   If the dialog window and the editor area do not overlap, or there is no
  188.   possibility of the highlight being covered don't move it. }
  189. var EditorScreen : TPoint;
  190.     SelectBottom : integer;
  191.     Metrics      : TTextMetric;
  192.     RowHeight    : integer;
  193. begin
  194.   EditorScreen := TheEditor.ClientToScreen(TheEditor.ClientRect.TopLeft);
  195.   if ((EditorScreen.X+TheEditor.Width) < SuggestDlg.Left) or
  196.      (EditorScreen.X > (SuggestDlg.Left+SuggestDlg.Width)) or
  197.      ((EditorScreen.Y+TheEditor.Height) < SuggestDlg.Top) or
  198.      (EditorScreen.Y > (SuggestDlg.Top+SuggestDlg.Height)) then
  199.     exit;  { Not in editor area so exit without bothering to move the dialog }
  200.  
  201.  { Figure out where the current line really is on the screen }
  202.  
  203.   { Get the Row Height }
  204.   TheEditor.Canvas.Font := TheEditor.FixedFont.Font;
  205.   GetTextMetrics(TheEditor.Canvas.Handle, Metrics);
  206.   RowHeight := Metrics.tmHeight+Metrics.tmExternalLeading+1;
  207.  
  208. (*
  209.   { Use this instead of the above three lines if you are using a
  210.     version of Orpheus earlier than v1.02. However, it is only accurate
  211.     for the default system font.                                        }
  212.   RowHeight := ABS(TheEditor.FixedFont.Font.Height)+3;
  213. *)
  214.  
  215.   SelectBottom := ((SelectLine-TheEditor.TopLine)+1)*RowHeight+EditorScreen.Y;
  216.   { See if the highlight could actually be covered by the dialog }
  217.   if (SelectBottom  < SuggestDlg.Top) or
  218.      ((SelectBottom-RowHeight) > (SuggestDlg.Top+SuggestDlg.Height)) then
  219.     exit;  { Not near the highlight, exit without moving }
  220.   { It could be covering the highlight, so move to the top or bottom of screen }
  221.   if SelectBottom > (Screen.Height div 2) then
  222.     SuggestDlg.Top := 20
  223.   else
  224.     SuggestDlg.Top := Screen.Height-SuggestDlg.Height-20;
  225. end;
  226.  
  227. procedure TOrphSpell.BaseCheckOrph(var TheEditor : TOvcCustomEditor;
  228.                                        StartLine : longint; StartCol : integer;
  229.                                        EndLine   : longint; EndCol   : integer);
  230. { The main method for this component.  Test the spelling of the text in the passed memo }
  231. var Done       : boolean;        { Loop control }
  232.     OldHide    : boolean;        { Storage for the original state of the HideSelection property }
  233.     Changed    : boolean;        { Was anything in the memo changed? }
  234.     EmptyList  : TStringList;    { Empty list in case user dictionary need to be made }
  235.     TheResult  : integer;        { Temporary storage for ShowModal return value }
  236.     Start      : integer;        { Start of the word }
  237.     WordEnd    : integer;        { End of the word }
  238.     CCol       : integer;        { Current column being checked }
  239.     CLine      : longint;        { Current line being checked }
  240.   function StripWord(L : STRING; VAR SCol : INTEGER; var EndCol : integer) : STRING;
  241.   BEGIN
  242.     { Scan for the start of a word }
  243.     WHILE (SCol<= Length(L)) AND (NOT (L[SCol] IN ['A'..'Z','a'..'z',#138,#140,#159,   { Skip any non-letters }
  244.                                          #192..#214,#216..#223,#240,
  245.                                          #154,#156,#224..#239,
  246.                                          #241..#246,#248..#255])) DO
  247.       BEGIN
  248.         Inc(SCol);
  249.       END;
  250.  
  251.     EndCol := SCol;   { Assume the end is the same as the start - i.e. one letter word }
  252.     IF SCol > Length(L) THEN           { No non-letter left on line, so no word found }
  253.       BEGIN
  254.         StripWord := '';
  255.         Exit;
  256.       END;
  257.     { Scan for the end of the word }
  258.     WHILE (EndCol <= Length(L)) AND (L[EndCol] IN ['A'..'Z','a'..'z',#138,#140,#159,   { Only add letters and "'" }
  259.                                      #192..#214,#216..#223,#240,
  260.                                      #154,#156,#224..#239,
  261.                                      #241..#246,#248..#255,'''']) DO
  262.       BEGIN
  263.         Inc(EndCol);
  264.       END;
  265.     StripWord := Copy(L,SCol,EndCol-SCol);     { Return the word we found }
  266.   END;
  267.   function GetNextWord : STRING;
  268.   BEGIN
  269.     GetNextWord := '';
  270.     WITH TheEditor DO
  271.       BEGIN
  272.         IF CCol > LineLength[CLine] THEN
  273.           BEGIN
  274.             Inc(CLine);
  275.             CCol := 1;
  276.           END;
  277.         IF CLine > LineCount THEN  { Passed the end of the editor get out of here }
  278.           Exit;
  279.         IF (CLine = LineCount) AND (CCol >= LineLength[CLine]) THEN    { Ditto }
  280.           Exit;
  281.         GetNextWord := StripWord(Lines[CLine], CCol, WordEnd);  { Get the text of the word }
  282.         Start := CCol;                      { Save where this word started }
  283.       END;
  284.   END;
  285. begin
  286.   try
  287.   Changed := FALSE;  { Nothing has been changed yet. }
  288.   OldHide := TheEditor.HideSelection;     { Save the old HideSelection property }
  289.   TheEditor.HideSelection := FALSE;        { and make sure selections are shown }
  290.   SuggestDlg.MaxSuggest := FSuggestMax;  { Set the maximum number of suggestions }
  291.  
  292.   if not FDictionaryOpen then  { Check to see if the dictionary is already open }
  293.     begin
  294.       FDictionaryOpen := BaseASpl.OpenDictionary(DictDataPtr, FDictionaryMain);  { Open the dictionaries }
  295.       if not FDictionaryOpen then
  296.         begin
  297.           MessageDlg('Could not open dictionary', mtError, [mbOK], -1);
  298.           exit;
  299.         end;
  300.       UserDictID := BaseASpl.OpenUserDictionary(DictDataPtr, FDictionaryUser);  { And record if they actually opened }
  301.       if UserDictID < 0 then        { Didn't open so try to make one }
  302.         begin
  303.           EmptyList := TStringList.Create;   { Create and clear to make an empty list }
  304.           EmptyList.Clear;
  305.           UserDictID := BaseASpl.BuildUserDictionary(DictDataPtr, FDictionaryUser, EmptyList);  { Build dictionary }
  306.           EmptyList.Free;  { Free the empty list }
  307.         end;
  308.       UserDictionaryOpen := UserDictID > 0;  { Check to see if dictionary was opened/made }
  309.     end;
  310.   with SuggestDlg do  { The suggestion dialog is used a lot so make it easily accessible }
  311.     begin
  312.       CCol  := StartCol;   { Set to beginning of section to spell check }
  313.       CLine := StartLine;
  314.       SuggestDlg.Caption := 'Suggestions: Scanning...';  { Tell the user we're scanning the text }
  315.       TheEditor.SetCaretPosition(1,1);  { Move to start of editor }
  316.       if FAvoidHighlight then  { Calculate a window position if avoiding the highlight }
  317.         begin
  318.           SuggestDlg.Top := (Screen.Height div 2) - (SuggestDlg.Height div 2);  { Position dialog in center of screen }
  319.           SuggestDlg.Left := (Screen.Width div 2) - (SuggestDlg.Width div 2);
  320.           SetDialogPosition(TheEditor,1);
  321.         end;
  322.       SuggestDlg.WordEdit.Text := '';   { Clear the fields in the dialog window }
  323.       SuggestDlg.SuggestList.Clear;
  324.       SuggestDlg.TheResult := 0;
  325.       SuggestDlg.DisableButtons;        { Disable all but the Cancel button }
  326.       Application.ProcessMessages;      { Give Windows time to draw the window }
  327.       Done := FALSE;            { Assume we aren't done }
  328.       repeat
  329.         StartWord := GetNextWord;       { Get the next word in the memo }
  330.         Application.ProcessMessages;    { Give Windows time to process mouse events }
  331.         if StartWord <> '' then
  332.           begin
  333.             IF not BaseASpl.GoodWord(DictDataPtr, StartWord) THEN  { Is the word in the dictionaries? }
  334.               if IgnoreList.IndexOf(Uppercase(StartWord)) = -1 then  { No, is it in the ignore list? }
  335.                 begin  { Word not found and not ignored }
  336.                   if WordEnd >= TheEditor.VisibleColumns then   { Make sure the highlight is visible }
  337.                     TheEditor.SetSelection(CLine, Start, CLine, WordEnd, TRUE)  { Force a scroll left if needed }
  338.                   else
  339.                     TheEditor.SetSelection(CLine, Start, CLine, WordEnd, FALSE);  { Force a Scroll right if needed }
  340.                   Application.ProcessMessages;   { Give Windows a little time to update things}
  341.                   if ReplaceList.IndexOf(StartWord) = -1 then  { In the replacement list? }
  342.                     begin  { No it isn't in the replace list }
  343.                       case FSuggestType of           { Build an inital list of suggestions }
  344.                         stCloseMatch : SuggestList.Items := BaseASpl.SuggestCloseMatch(DictDataPtr, StartWord, FSuggestMax);
  345.                         stPhoneme    : SuggestList.Items := BaseASpl.SuggestPhoneme(DictDataPtr, StartWord, FSuggestMax);
  346.                         stNoSuggest  : SuggestList.Clear;
  347.                       end;
  348.                       SuggestDlg.TheResult := 0;              { Clear the Dialog result }
  349.                       SuggestDlg.Caption := 'Suggestions';    { Remove "Scanning" from caption }
  350.                       if FAvoidHighlight then                 { Check if the highlight has to be avoided }
  351.                         SetDialogPosition(TheEditor,CLine);
  352.                       if not SuggestDlg.Visible then          { If dialog isn't visible, make it so }
  353.                         SuggestDlg.Show;
  354.                       SuggestDlg.EnableButtons;      { Enable all the dialog controls }
  355.                       WordEdit.Text := StartWord;    { Setup the Suggestion dialog }
  356.                       NotWord.Text := StartWord;     { Setup the Word we are checking }
  357.                       ActiveControl := BtnIgnore;    { Make the Ignore Button active control }
  358.                       Application.ProcessMessages;   { Allow Windows to update things }
  359.  
  360.                       repeat                            { Give Windows all the time until }
  361.                          Application.ProcessMessages;   { one of the buttons are pressed }
  362.                       until SuggestDlg.TheResult <> 0;
  363.                       SuggestDlg.DisableButtons;    { Disable the buttons }
  364.                       TheResult := SuggestDlg.TheResult;  { Find out what the user did }
  365.                    end
  366.                   else
  367.                     begin
  368.                       TheResult := 101;  { Fake Replace Button being pressed }
  369.                       WordEdit.Text := AlternateList.Strings[ReplaceList.IndexOf(StartWord)]; { And get the replacement word }
  370.                     end;
  371.                    case TheResult of   { Do what the user told us }
  372.                     100 : Done := TRUE;                            { Cancel - end the spell checking }
  373.                     101,
  374.                     105 : begin
  375.                             { Replace - replace the word with the correction }
  376.                             TheEditor.Replace(StartWord, WordEdit.Text, [soReplace, soSelText]);
  377.                             Changed := TRUE;
  378.                             { Reset the end of word counter to reflect possible difference in word lengths }
  379.                             WordEnd := WordEnd + (Length(WordEdit.Text) - Length(StartWord));
  380.                             if CLine = EndLine then  { If this is the last line to test reset the ending column }
  381.                               EndCol := EndCol + (Length(WordEdit.Text) - Length(StartWord));
  382.                             if TheResult = 105 then { Replace all occurences }
  383.                               begin
  384.                                 ReplaceList.Add(StartWord);
  385.                                 AlternateList.Add(WordEdit.Text);
  386.                               end;
  387.                           end;
  388.                          { Add - the questioned word to the user dictionary }
  389.                     102 : BaseASpl.AddWord(DictDataPtr, StartWord, UserDictID);
  390.                     103 : ; { Ignore just this occurence - Dont' do anything }
  391.                          { Ignore All occurences - add the questioned word to the ignore list }
  392.                     104 : IgnoreList.Add(Uppercase(StartWord));
  393.                   end;
  394.                   SuggestDlg.Caption := 'Suggestions: Scanning...';  { Did something Return to scanning... }
  395.                 end;
  396.           end;
  397.         CCol := WordEnd+1;  { Move to one character after the end of the current word }
  398.       until Done or ((CLine >= EndLine) and (CCol >= EndCol)) or (SuggestDlg.TheResult = 100);
  399.      { Canceled or end of the editor is reached }
  400.     end;
  401.   TheEditor.SetSelection(1, 1, 1, 1, TRUE);   { Move to the top of the editor }
  402.   if SuggestDlg.Visible then   { Get rid of the dialog, if needed }
  403.     SuggestDlg.Hide;
  404.   if not Changed then    { Let the user know something actually happened }
  405.     MessageDlg('No changes made', mtInformation, [mbOK], -1)
  406.   else
  407.     MessageDlg('Checking complete', mtInformation, [mbOK], -1);
  408.   finally
  409.     if SuggestDlg.Visible then   { Get rid of the dialog, if needed }
  410.       SuggestDlg.Hide;
  411.     if not FLeaveDictionaryOpen then  { Check if the dictionaries should be closed }
  412.       begin
  413.         BaseASpl.CloseDictionaries(DictDataPtr);       { Close the dictionaries  }
  414.         FDictionaryOpen := FALSE;          { Mark them as not opened }
  415.         UserDictionaryOpen := FALSE;
  416.       end;
  417.     TheEditor.HideSelection := OldHide; { Restore the HideSelection property of the memo }
  418.   end;
  419. end;
  420.  
  421. procedure TOrphSpell.CheckOrph(TheEditor : TOvcCustomEditor);
  422. begin
  423.   { Call the base function to check the entire Editor }
  424.   BaseCheckOrph(TheEditor, 1,1, TheEditor.LineCount, TheEditor.LineLength[TheEditor.LineCount]);
  425. end;
  426.  
  427. procedure TOrphSpell.CheckOrphSelection(TheEditor : TOvcCustomEditor);
  428. var StartLine, EndLine : longint;
  429.     StartCol, EndCol   : integer;
  430.     S                  : string;
  431. begin
  432.   { If nothing is selected then just exit since there is nothing to check }
  433.   if not TheEditor.GetSelection(StartLine, StartCol, EndLine, EndCol) then
  434.     exit;
  435.  { Scan backward to make sure we're at the beginning of a word }
  436.   S := TheEditor.Lines[StartLine];
  437.   WHILE (StartCol > 0) AND (S[StartCol] IN ['A'..'Z','a'..'z',#138,#140,#159,
  438.                                             #192..#214,#216..#223,#240,
  439.                                             #154,#156,#224..#239,
  440.                                             #241..#246,#248..#255]) DO
  441.     Dec(StartCol);
  442.   IF StartCol = 0 THEN
  443.     StartCol := 1;
  444.  { Scan forward to make sure we have a whole word at the end of the selection }
  445.   S := TheEditor.Lines[EndLine];
  446.   Dec(EndCol);
  447.   if EndCol < 0 then
  448.     EndCol := 0;
  449.   while (EndCol < Length(S)) and (S[EndCol] in ['A'..'Z','a'..'z',#138,#140,#159,
  450.                                                 #192..#214,#216..#223,#240,
  451.                                                 #154,#156,#224..#239,
  452.                                                 #241..#246,#248..#255]) DO
  453.     Inc(EndCol);
  454.   if EndCol > Length(S) then
  455.     EndCol := Length(S);
  456.   BaseCheckOrph(TheEditor, StartLine,StartCol, EndLine,EndCol);
  457. end;
  458.  
  459.  
  460. end.
  461.